
$(document).ready(function () {	
	findPlanById();
});

function findPlanById(){	
	var timestamp = Date.parse(new Date());
	
	/*
	var planid=getCookie(PId);
	//var planid="1000000011";
	if(planid==null||planid==undefined){
		//alert("nullo");
		planid=$('#haohuaxiangq').text();
	}*/
	
	var planid=$('#haohuaxiangq').text();
	//var planid="1000000011";
	if(planid==null||planid==undefined||planid==""){
		//alert("nullo");
		planid=getCookie(PId);
	}
	//alert(planid+"planid");
	
	$.get("lzm/Plan_findPlanById.action?ts="+timestamp+"&PId="+planid,null,findPlanByIdRst);
}

function findPlanByIdRst(data){
	var plan=data.tbPlan;
	$('#PId').text(plan.PId);
	$('#PName').text(plan.PName);
	$('#planType').text(plan.tbPlanType.ptName);
	$('#planGrade').text(plan.tbPlanGrade.pgName);
	$('#eventType').text(plan.tbEventType.etEventType);
	$('#planScope').text(plan.tbPlanScope.psName);
	$('#planRegion').text(plan.tbPlanRegion.prName);
	$('#PSummary').text(plan.PSummary);
	$('#PUnit').text(plan.PUnit);
	$('#PContractor').text(plan.PContractor);
	$('#PTime').text(plan.PTime.replace(/T/," "));
	$('#PVersion').text(plan.PVersion);	
	var uDepts=new Array(plan.tbPlanKeywords.length);
	$.each(plan.tbPlanKeywords,function(i,n){
		//alert(n.tbUserDepts.udName);
		uDepts[i] = "  "+n.pkContent ;
	});
	var strhtml1="";
	strhtml1+=uDepts;
	$('#tbPlanKeywords').text(strhtml1);	
	/**
	 * 下面是处理预案的附件
	 */
	//alert(data.basePath);
	$.each(plan.tbPlanAnnexes,function(i,n){
		var tempObjTR = null;
   		tempObjTR = $("#trCache").clone(true);
		tempObjTR.find('.cntFrame').attr("src",n.c);
		tempObjTR.find('.planAnnexName').text(n.paDetail);
		var url="/ag/file/download.action?fileRealName="+n.paDetail+"&fileDiskURL="+n.paName+"&moduleID=101";
		tempObjTR.find('.fileUrl').text(url);
		$('#helpTBODY').prepend(tempObjTR);
		tempObjTR = null;
	});
	$.each(plan.tbPlanSteps,function(i,n){
		//alert(n.psName);
		//alert(n.psContent);
		var tempObj2=insertNodeConduct(n.psName,n.psContent,n.c);
		$.each(n.tbPsContents,function(i,n){
			//alert(n.pscContent);
			insertStepCntConduct(n.tbLogType.ltName,n.pscContent,tempObj2.find('.planStepCntSure'));
		});
	});
	$('.planAnnexName').click(function () {
		window.location.href=$(this).next().text();
	});
	$('.download').click(function () {
		window.location.href=$(this).prev().text();
	});
}

function insertNodeConduct(psName,psContent,c){
	//alert("dfsdf");
	//$('#intStep').text
	var tempObj1=$("#stepTemplate").clone();
	var tempObj2;
	tempObj2=tempObj1;
	//intStep++;
	//tempObj2.find('.intStepSP').text("环节"+intStep);
	tempObj2.find('.stepName').text("暂无");
	tempObj2.find('.stepDesc').text("暂无");
	tempObj2.find('.stepNote').text("暂无");
	tempObj2.find('.stepName').text(psName);
	tempObj2.find('.stepDesc').text(psContent);	
	tempObj2.find('.stepNote').text(c);
	//tempObj2.find('.stepDesc').text($("#stepDesc", window.frames["addPlanNode"].document).val());
	//tempObj2.find('.stepNote').text($("#stepNote", window.frames["addPlanNode"].document).val());
	$('#planStepSure').append(tempObj2); 
	return tempObj2;
	/*
	tempObj2.find('.divBorder1').html("");
	tempObj2.find('.countTag').text(0);	
	//$('#planStepCntSure').html("");
	//tempObj.prependTo("#planStepSure"); 
	$('#planStepSure').append(tempObj2); 
	$('.addPlanStepCnt').unbind("click");
	$('.addPlanStepCnt').click(function(){
		stepCntObj=$(this);
		addPlanStepCnt();
    });*/
}

function insertStepCntConduct(ltName,pscContent,tpObj){
	//alert("insertStepCntConduct");
	var tempObj1=$("#stepCntTemplate").clone();
	var tempObj2;
	tempObj2=tempObj1;
	//intCnt++;
	/*
	var intCnt=parseInt(stepCntObj.prev().text());
	intCnt++;
	stepCntObj.prev().text(intCnt);*/
	//tempObj2.find('.intCntSP').text("环节内容"+intCnt);
	//tpObj.find('.tbLogType').text();
	tempObj2.find('.tbLogType').text(ltName);
	tempObj2.find('.pscContent').text(pscContent);
	tpObj.append(tempObj2);
	/*
	tempObj2.find('.tbLogType').text($("#tbLogType option:selected'", window.frames["addPlanNode1"].document).text());
	tempObj2.find('.tbLogTypeID').text($("#tbLogType option:selected'", window.frames["addPlanNode1"].document).val());
	tempObj2.find('.pscContent').text($("#pscContent", window.frames["addPlanNode1"].document).val());
	stepCntObj.next().append(tempObj2);*/
	//$('#planStepCntSure').append(tempObj2);
	//tempObj2.prependTo("#planStepCntSure"); addStepCnt
}